__author__ = 'dong'

from app.models import Book
from rest_framework import serializers

class BookSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Book
        fields = ('name', 'title', 'author')

    def restore_object(self, attrs, instance=None):
        if instance:
            instance.name = attrs['name']
            instance.title = attrs['title']
            instance.author = attrs['author']
            return instance

        return Book(**attrs)